18A - Triangle - CodeForces Solution


brute force geometry *1500

Please click on ads to support us..

C++ Code:

#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>

using namespace std;

int distance(int a,int b,int x,int y){
	return ((a -x)*(a-x) + (b-y)*(b-y));
}

bool check(vector<int> cod){
	int d1,d2,d3;
	unsigned int i=0;
	for(i=0;i<cod.size();i+=1){
		cod[i]-=1;
		d1=distance(cod[0],cod[1],cod[2],cod[3]);
		d2=distance(cod[0],cod[1],cod[4],cod[5]);
		d3=distance(cod[2],cod[3],cod[4],cod[5]);
		cod[i]+=1;
		//cout<<d1<<" "<<d2<<" "<<d3<<endl;
		if(d1 == 0 or d2 ==0 or d3 == 0)
			continue;
		if( (d1 == d2 + d3) or (d2 == d1 + d3) or (d3 == d2 + d1)){
			//cout<<d1<<" "<<d2<<" "<<d3<<endl;
			return 1;
			}
	}
	for(i=0;i<cod.size();i+=1){
		cod[i]+=1;
		d1=distance(cod[0],cod[1],cod[2],cod[3]);
		d2=distance(cod[0],cod[1],cod[4],cod[5]);
		d3=distance(cod[2],cod[3],cod[4],cod[5]);
		//cout<<cod[0]<<" "<<cod[1]<<" "<<cod[2]<<" "<<cod[3]<<" "<<cod[4]<<" "<<cod[5]<<endl;
		//cout<<d1<<" "<<d2<<" "<<d3<<endl;
		cod[i]-=1;
		if(d1 == 0 or d2 ==0 or d3 == 0)
			continue;
		if( (d1 == d2 + d3) or (d2 == d1 + d3) or (d3 == d2 + d1)){
			//cout<<d1<<" "<<d2<<" "<<d3<<endl;
			return 1;
			}
	}
	return 0;
}

int main(){
	vector<int> cod;
	unsigned int i;
	for(i=0;i<6;i+=1){
		int temp;
		cin>>temp;
		cod.push_back(temp);
	}
	int d1,d2,d3;
	d1=distance(cod[0],cod[1],cod[2],cod[3]);
	d2=distance(cod[0],cod[1],cod[4],cod[5]);
	d3=distance(cod[2],cod[3],cod[4],cod[5]);
	//cout<<d1<<" "<<d2<<" "<<d3<<endl;
	if( (d1 == d2 + d3) or (d2 == d1 + d3) or (d3 == d2 + d1)){
		cout<<"RIGHT"<<endl;
		return 0;
		}
	else if( check(cod))
		cout<<"ALMOST"<<endl;
	else
		cout<<"NEITHER"<<endl;
	return 0;
}


Comments

Submit
0 Comments
More Questions

732B - Cormen --- The Best Friend Of a Man
1369A - FashionabLee
1474B - Different Divisors
1632B - Roof Construction
388A - Fox and Box Accumulation
451A - Game With Sticks
768A - Oath of the Night's Watch
156C - Cipher
545D - Queue
459B - Pashmak and Flowers
1538A - Stone Game
1454C - Sequence Transformation
165B - Burning Midnight Oil
17A - Noldbach problem
1350A - Orac and Factors
1373A - Donut Shops
26A - Almost Prime
1656E - Equal Tree Sums
1656B - Subtract Operation
1656A - Good Pairs
1367A - Short Substrings
87A - Trains
664A - Complicated GCD
1635D - Infinite Set
1462A - Favorite Sequence
1445B - Elimination
1656C - Make Equal With Mod
567A - Lineland Mail
1553A - Digits Sum
1359B - New Theatre Square